<?php

class XQL_Simple_GetQuery extends XQL_SimpleQuery
{
	protected $isResultSingleRow = TRUE;

	public function __construct($querySetName, $connectionAlias='default')
	{
		parent::__construct($querySetName, $connectionAlias);

		if (!$this->isQueryLoaded())
		{
			$this->setAction(
				XQL_Select::create()->
				join(
					XQL_Enumerator::create()->set(
						XQL_Field::create()->set('*')
					)
				)->
				join(
					XQL_From::create()->set(
						XQL_Table::create()->set(
							XQL_Item::create()->set(':table')
						)
					)
				)->
				join(
					XQL_Where::create()->set(
						XQL_Item::create()->set(':where')
					)
				)
			);
		}
	}

	/**
	 * Visszad egy példányt az osztályból.
	 *
	 * @return XQL_Simple_GetQuery
	 */
	static public function create($querySetName, $connectionAlias='default')
	{
		return new XQL_Simple_GetQuery($querySetName, $connectionAlias);
	} // static method

	protected function onBeforeExecute($args)
	{
		if ($this->hasTransformableData())
		{
			$args = $this->dataTransformation->encodeRecord($args);
		}
		$wherePartString = XQL_Util::argumentToFilter($this->keysToFormatArray());
		$rep = array(
			':table'	=> (string)$this->table,
			':where'	=> (string)$wherePartString
		);
		$this->query = str_replace(array_keys($rep), array_values($rep), $this->query);

		return $this;
	}

	protected function onAfterExecute($resultset, $args)
	{
		if ($this->hasTransformableData())
		{
			$resultset = $this->dataTransformation->decodeRecord($resultset);
		}
		return $resultset;
	}
}

?>